home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / security / shadow-3.1.4 / scologin.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-26  |  1.8 KB  |  89 lines

  1. /*
  2.  * Copyright 1991, John F. Haugh II and Chip Rosenthal
  3.  * All rights reserved.
  4.  *
  5.  * Permission is granted to copy and create derivative works for any
  6.  * non-commercial purpose, provided this copyright notice is preserved
  7.  * in all copies of source code, or included in human readable form
  8.  * and conspicuously displayed on all copies of object code or
  9.  * distribution media.
  10.  */
  11.  
  12. #ifndef lint
  13. static    char    sccsid[] = "@(#)scologin.c    3.2    14:38:24    10/27/91";
  14. #endif
  15.  
  16. #include <stdio.h>
  17. #include "pwd.h"
  18.  
  19. #define USAGE    "usage: %s [ -r remote_host remote_user local_user [ term_type ] ]\n"
  20. #define LOGIN    "/etc/login"
  21.  
  22. extern int errno;
  23. extern char *sys_errlist[];
  24. extern char **environ;
  25.  
  26. main(argc, argv)
  27. int argc;
  28. char *argv[];
  29. {
  30.     char *rhost, *ruser, *luser;
  31.     char term[1024], *nargv[8], *nenvp[2];
  32.     int root_user, i;
  33.     struct passwd *pw;
  34.  
  35.     if (argc == 1) {
  36.  
  37.         /*
  38.          * Called from telnetd.
  39.          */
  40.         nargv[0] = "login";
  41.         nargv[1] = "-p";
  42.         nargv[2] = NULL;
  43.  
  44.     } else if (strcmp(argv[1], "-r") == 0 && argc >= 6) {
  45.  
  46.         /*
  47.          * Called from rlogind.
  48.          */
  49.  
  50.         rhost = argv[2];
  51.         ruser = argv[3];
  52.         luser = argv[4];
  53.         root_user = ((pw = getpwnam(luser)) != NULL && pw->pw_uid == 0);
  54.  
  55.         i = 0;
  56.         if ( argc == 6 ) {
  57.             strcpy(term, "TERM=");
  58.             strncat(term+sizeof("TERM=")-1,
  59.                 argv[5], sizeof(term)-sizeof("TERM="));
  60.             term[sizeof(term)-1] = '\0';
  61.             nenvp[i++] = term;
  62.         }
  63.         nenvp[i++] = NULL;
  64.         environ = nenvp;
  65.  
  66.         i = 0;
  67.         nargv[i++] = "login";
  68.         nargv[i++] = "-p";
  69.         nargv[i++] = "-h";
  70.         nargv[i++] = rhost;
  71.         if (ruserok(rhost, root_user, ruser, luser) == 0)
  72.             nargv[i++] = "-f";
  73.         nargv[i++] = luser;
  74.         nargv[i++] = NULL;
  75.  
  76.     } else {
  77.  
  78.         fprintf(stderr, USAGE, argv[0]);
  79.         exit(1);
  80.  
  81.     }
  82.  
  83.     (void) execv(LOGIN, nargv);
  84.     fprintf(stderr, "%s: could not exec '%s' [%s]\n",
  85.         argv[0], LOGIN, sys_errlist[errno]);
  86.     exit(1);
  87.     /*NOTREACHED*/
  88. }
  89.